package com.hxx.controller;

import dev.langchain4j.data.message.AiMessage;
import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.output.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TwoController {

    @Autowired
    private ChatLanguageModel chatLanguageModel;

    @GetMapping("/chat2")
    public String chat2(String prompt) {
        //用户输入的信息
        UserMessage userMessage = UserMessage.from(prompt);
        //大语言模型的响应
        Response<AiMessage> response = chatLanguageModel.generate(userMessage);
        //ai输出
        AiMessage content = response.content();
        return content.text();
    }
}



























